package cn._51doit.flink.day04;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 将多个类型一样的DataStream合并成一个DataStream，以后可以统计对一个DataStream进行操作
 */
public class UnionDemo1 {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //5
        //6
        DataStreamSource<String> lines1 = env.socketTextStream("localhost", 8888);
        SingleOutputStreamOperator<Integer> nums1 = lines1.map(Integer::parseInt).setParallelism(3);

        DataStreamSource<String> lines2 = env.socketTextStream("localhost", 9999);
        SingleOutputStreamOperator<Integer> nums2 = lines2.map(Integer::parseInt);

        //将两个或多个dataStrea合并到一起
        DataStream<Integer> res = nums1.union(nums2);

        //一个DataStream union自己会将数据双倍
        //DataStream<Integer> res = nums1.union(nums1);

        res.print();

        env.execute();

    }
}
